package com.example.readfiletest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ZichanDetailActivity extends Activity {


	private TextView codeTv;
	private TextView address;
	private TextView productName;
	private TextView buildArea;
	private TextView brand;
	private TextView xinghao;
	private TextView passportNo;
	private TextView productNo;
	private TextView pandianFlg;
	private TextView pandianDate;
	
	private Button checkConsistBtn;
	private Button checkNoConsistBtn;
	
	private Bundle bundle;
	
	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			String message = msg.getData().getString("barcode");
			//tv.setText(message);
			codeTv.setText(message);
			message = msg.getData().getString("productname");
			productName.setText(message);
			message = msg.getData().getString("address");
			address.setText(message);
			message = msg.getData().getString("buildarea");
			buildArea.setText(message);
			message = msg.getData().getString("brand");
			brand.setText(message);
			message = msg.getData().getString("xinghao");
			xinghao.setText(message);
			message = msg.getData().getString("passportno");
			passportNo.setText(message);
			message = msg.getData().getString("productno");
			productNo.setText(message);
			message = msg.getData().getString("pandianflg");
			pandianFlg.setText(message);
			message = msg.getData().getString("pandiandate");
			pandianDate.setText(message);
			
			bundle = msg.getData();
		};
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_zichan_detail);
		
		codeTv = (TextView) findViewById(R.id.code_tv);
        address = (TextView) findViewById(R.id.adress_tv);
    	productName = (TextView) findViewById(R.id.zichan_tv);
    	buildArea = (TextView) findViewById(R.id.buildarea_tv); 
    	brand = (TextView) findViewById(R.id.brand_tv);
    	xinghao = (TextView) findViewById(R.id.xinghao_tv);
    	passportNo = (TextView) findViewById(R.id.passport_tv);
    	productNo = (TextView) findViewById(R.id.productno_tv);
    	pandianFlg = (TextView) findViewById(R.id.ispandian_tv);
    	pandianDate = (TextView) findViewById(R.id.pandian_date_tv);
    	
    	checkConsistBtn = (Button) findViewById(R.id.check_consist_btn);
    	checkNoConsistBtn = (Button) findViewById(R.id.check_no_consist_btn);
    	
    	
    	Intent intent = getIntent();
    	final String searchbyBarcode = intent.getExtras().getString(ZichanConstants.SEARCHBYBARCODE);
    	
    	new Thread() {
			@Override
			public void run() {
				
				super.run();
				//bufferRead();
				//readRandom();
				PandianFileUtils.searchRecord(handler,searchbyBarcode);
			}

			
		}.start();
		
		
		checkConsistBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
			}
		});
		
		checkNoConsistBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ZichanDetailActivity.this, ZichanModifyActivity.class);
				intent.putExtras(bundle);
				startActivity(intent);
			}
		});
		
	}

	
}
